/*
 * @Descripttion:
 * @Author: voanit
 * @Date: 2022-09-15 17:49:58
 * @LastEditors: voanit
 * @LastEditTime: 2022-09-15 17:56:41
 */
/* 需求

http://www.baidu.com?id=123&name=jack=====>1或者jack
*/
function searchParams(key) {
  var obj = {}
  var url = 'http://www.baidu.com?id=123&name=jack'
  var searchUrl = url.split('?')[1] //id=123&name=jack
  var arr = searchUrl.split('&') // ['id=123','name=jack]
  console.log(arr, 6)
  arr.forEach((item) => {
    var newArr = item.split('=') //[id,1]   [name,jack]
    obj[newArr[0]] = newArr[1] //{id:1,name:jack}
  })
  return obj[key]
}

console.log(searchParams('id')) //123
console.log(searchParams('name')) //123
